package org.fullhappy.rest.filter;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerRequestFilter;

public class RequestFilter implements ContainerRequestFilter {

	@Override
	public ContainerRequest filter(ContainerRequest request) {
		String path = request.getRequestUri().getPath();
		String uriPath = request.getBaseUri().getPath();
		String referer = request.getHeaderValue("Referer");
		String host = request.getBaseUri().toString();
		if(uriPath.length()>1){
			host = host.substring(0, host.indexOf(uriPath));
			path = path.substring(uriPath.length());
		}
		
//		if( path.indexOf("resources") == 0 || (""+referer).indexOf(host)!=0){
//			 Response denied = Response.status(Response.Status.FORBIDDEN).entity("Permission Denied").build();
//			 throw new WebApplicationException(denied);
//		}
		
		return request;
	}
}
